package com.yogee.topseller.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yogee.topseller.R;
import com.yogee.topseller.bean.MessageInfoBean;

import java.nio.channels.NonReadableChannelException;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @auathor ${XiaoJianghong}
 * @date 2017/7/14.
 */

public class NoticeRvAdapter extends RecyclerView.Adapter<NoticeRvAdapter.ItemHolder> {

    private Context context;
    private int type;
    private List<MessageInfoBean.MessageBean> data;

    public NoticeRvAdapter(Context context, int type) {
        this.context = context;
        this.type = type;
    }

    public void addData(List<MessageInfoBean.MessageBean> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    @Override
    public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_notice, parent, false);
        return new ItemHolder(view);
    }

    @Override
    public void onBindViewHolder(ItemHolder holder, int position) {
        switch (type) {
            case 0:
                holder.iv.setImageResource(R.mipmap.steward_xi_blue_s2);
                break;
            case 1:
                holder.iv.setImageResource(R.mipmap.steward_dress_red_s2);
                break;
            case 2:
                holder.iv.setImageResource(R.mipmap.steward_general_yellow_s2);
                break;
        }
        MessageInfoBean.MessageBean bean = data.get(position);
        holder.textTv.setText(bean.getCenter());
        holder.tiemTv.setText(bean.getTime());
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    public class ItemHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_notice_iv)
        ImageView iv;
        @BindView(R.id.item_notice_text_tv)
        TextView textTv;
        @BindView(R.id.item_notice_tiem_tv)
        TextView tiemTv;
        @BindView(R.id.item_notice_rl)
        RelativeLayout noticeRl;

        public ItemHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
